package com.hanbang.maige.pressenter.huodong;

import android.support.design.widget.Snackbar;

import com.hanbang.maige.code.base.presenter.BasePresenter;
import com.hanbang.maige.mode.HttpRequest;
import com.hanbang.maige.mode.httpresponse.BaseHttpResponse;
import com.hanbang.maige.mode.javabean.huodong.HuoDongPublishData;
import com.hanbang.maige.utils.http.httpquest.HttpCallBack;
import com.hanbang.maige.utils.http.httpquest.HttpRequestParam;
import com.hanbang.maige.utils.ui.SnackbarUtil;
import com.hanbang.maige.view.huodong.IHuoDongBaseView;

/**
 * 作者　　: 方朝辉
 * 创建时间:2016/10/25
 * <p>
 * <p>
 * 功能介绍：
 */

public class PublishHuoDongPresenter extends BasePresenter<IHuoDongBaseView.IPublishHuoDongView> {

    /**
     * 作者　　: 李坤
     * 创建时间: 2016/10/26 14:33
     * 发布活动	AddActive	ActivityName：活动名称
     * starttime:开始时间
     * endtime:结束时间
     * ActivityAddress：活动地址
     * ActiveJieShao:活动介绍
     * ActiveBiaoqian:活动标签
     * huodong:海报
     * <p>
     * {
     * "Result": 0,
     * "Msg": "发布成功！"
     * }
     */

    public void postHuodong(HuoDongPublishData huoDongPublishData) {
        if (huoDongPublishData == null) return;
        HttpCallBack.Buider buider = new HttpCallBack.Buider(this);
        buider.setHint("活动发布中");
        HttpCallBack<BaseHttpResponse> callBack = new HttpCallBack<BaseHttpResponse>(buider) {
            @Override
            public void onSuccess(BaseHttpResponse result) {
                super.onSuccess(result);
                if (result.isSucceed()) {
                    mvpView.showSnackbar(result.getMsg(), SnackbarUtil.Info, true, new Snackbar.Callback() {
                        @Override
                        public void onDismissed(Snackbar snackbar, int event) {
                            super.onDismissed(snackbar, event);
                            mvpView.complete();
                        }
                    });
                } else {
                    mvpView.showErrorSnackbar(result.getMsg());
                }
            }
        };

        HttpRequestParam param = new HttpRequestParam("AddActive");
        param.addParam("ActivityName", huoDongPublishData.name);
        param.addParam("starttime", huoDongPublishData.getStartDate());
        param.addParam("endtime", huoDongPublishData.getEndDate());
        param.addParam("ActivityAddress", huoDongPublishData.huodongAddress);
        param.addParam("ActiveJieShao", huoDongPublishData.huodongJieShao);
        param.addParam("ActiveBiaoqian", huoDongPublishData.getBiaoQianId());
        param.addParam("ActiveRenshu", huoDongPublishData.huodongRenshu);
        param.addParamFile("huodong", huoDongPublishData.haibaoPath);
        mvpView.addSubscription(HttpRequest.uploadFiles(callBack, param));

    }
}
